<form>
  <aside class="lg-side">
    <div class="panel-heading tab-bg-dark-navy-blue okr-tab-head tab-right "></div>
    <div class="inbox-body mi-h8">
      <div class="row">
        <div class="col-lg-12">
          <section class="panel">
            <header class="panel-heading">
              客户信息
            </header>
            <div class="panel-body">
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">区域*</label>
                <div class="col-sm-10">
                  <select name="area" id="area" class="form-control" certus-required>
                    <option value="">请选择</option>
                    <option ng-repeat="d in area" value="{{d.regionCode}}">{{d.region}}</option>
                  </select>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">行业*</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" value="" id="industry" name="industry" placeholder="行业"
                    onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">客户名称*</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" value="" id="comName" name="comName" placeholder="客户名称"
                    onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">客户简称*</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" value="" id="comShortName" name="comShortName"
                    placeholder="客户简称" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">我司负责人*</label>
                <div class="col-sm-10">
                  <input type="text" id="autocomplete" value="" aria-invalid="userName" class="form-control"
                    placeholder="负责人姓名" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                  <input type="hidden" value="" name="userId" id="userId" />
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">客户类型</label>
                <div class="col-sm-10">
                  <select class="form-control" id="comType" name="comType">
                    <option value="">请选择</option>
                    <option value="销售">销售</option>
                  </select>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">联系方式</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" value="" id="telephone" name="telephone"
                    onkeyup="clearNoNum(this)" onblur="telNo(this.id)">
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">地址</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" value="" id="address" name="address" placeholder="地址描述"
                    onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">客户背景介绍</label>
                <div class="col-sm-10">
                  <textarea class="form-control" id="comBackDesc" name="comBackDesc" maxlength="120"
                    placeholder="字数限制(120字以内)" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"></textarea>
                </div>
              </div>
              <input type="hidden" value="" name="id" id="tid" />
              <p class="default-buttons">
                <a href="javascript:void(0);" class="button-back btn btn-info" onclick="toBack()">返回</a>
                <a href="javascript:void(0);" class="button-next  btn btn-info submit">提交</a>
              </p>
            </div>
          </section>
        </div>
      </div>
    </div>
  </aside>
</form>
<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
<script>
  function findComInfo($certusUtils, $$scope, id) {
      CertusFormAjax.ajax("findQYList",{},function (response) {
          $scope.area = response.data;
      });

    $certusUtils.ajax("findSpUserList", {}, function (response) {
      var nhlTeams = [];
      var data = response.data;
      for (var i = 0; i < data.length; i++) {
        var arr = {};
        arr.name = data[i].userName + "[" + data[i].positonName + "]";
        arr.id = data[i].userId;
        nhlTeams.push(arr);
      }
      //自动补全
      var nhl = $.map(nhlTeams, function (obj) {
        return {
          value: obj.name,
          data: {
            category: obj.id
          }
        };
      });
      // Initialize autocomplete with local lookup:
      $('#autocomplete').devbridgeAutocomplete({
        lookup: nhl,
        minChars: 1,
        onSelect: function (suggestion) {
          $("#userId").val(suggestion.data.category);
        },
        showNoSuggestionNotice: true,
        noSuggestionNotice: 'Sorry, no matching results'
      });
    });

    $certusUtils.ajax("findProComInfo", {
      "id": id
    }, function (response) {
      var data = response.data;
      $("#area").val(data.area);
      $("#industry").val(data.industry);
      $("#comName").val(data.com_name);
      $("#comShortName").val(data.com_short_name);
      $("#autocomplete").val(data.user_name);
      $("#userId").val(data.user_id);
      $("#comType").val(data.com_type);
      $("#telephone").val(data.telephone);
      $("#address").val(data.address);
      $("#comBackDesc").val(data.com_back_desc);
      $("#tid").val(data.id);
    });
    $(".submit").on('click', function () {
      var arr = $("form").serializeArray();
      var data = {};
      for (var i = 0; i < arr.length; i++) {
        data[arr[i].name] = arr[i].value;
      };

      if (data.area == "" || data.area == null || data.area == undefined) {
        layer.msg("区域选择不能为空！");
        return;
      }
      if (data.industry == "" || data.industry == null || data.industry == undefined) {
        layer.msg("行业不能为空！");
        return;
      }
      if (data.comName == "" || data.comName == null || data.comName == undefined) {
        layer.msg("客户名称不能为空！");
        return;
      }
      if (data.comShortName == "" || data.comShortName == null || data.comShortName == undefined) {
        layer.msg("客户简称不能为空！");
        return;
      }
      if (data.userId == "" || data.userId == null || data.userId == undefined) {
        layer.msg("我司负责人不能为空！");
        return;
      }
      $certusUtils.ajax("updateComInfo",{"data":JSON.stringify(data),"projId":proId},function () {
          layer.msg("更新成功");
      });
      toLoadHtml(5);
    });
  }

  function toBack() {
    toLoadHtml(5);
  }
</script>